<?php


require_once '/data/wwwroot/package/vendor/autoload.php';

/**
 * https://packagist.org/packages/elasticsearch/elasticsearch
*/
try {
    $client = \Elasticsearch\ClientBuilder::create()->setBasicAuthentication('elastic', 'DV0HUI9aVqePucg07JaN')->build();
    //
    $rs = $client->ping();

    var_dump($rs);
    //新增数据
//    $rs = $client->index([
//        'index' => 'my-daily',
//        'id'    => '3',
//        'body'  => ['testField' => ['elasticsearch', 'hello']]
//    ]);
    $rs = $client->update([
        'index' => 'my-daily',
        'id'    => '3',
        'body'  => ['testField' => 'elasticsearch']
    ]);
//
//    $rs = $client->search([
//        'index' => 'my-daily',
//        'body'  => [
//            'query' => [
//                'match' => [
//                    'testField' => 'abc'
//                ]
//            ]
//        ]
//    ]);
//    var_dump($rs);

    $client = new \GuzzleHttp\Client([
        // Base URI is used with relative requests
        'base_uri' => 'http://elastic:haohaozhu.me@localhost:9200',
        // You can set any number of default request options.
        'timeout'  => 2.0,
    ]);


    $response = $client->request('GET', '');
    var_dump($response->getStatusCode(), $response->getBody()->getContents());
} catch (Exception $e) {
    echo $e->getMessage();
}



